package cn.iocoder.yudao.module.yyzx.controller.admin.nurse_content;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotations.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_content.vo.*;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.nurse_content.Nurse_contentDO;
import cn.iocoder.yudao.module.yyzx.service.nurse_content.Nurse_contentService;

@Tag(name = "管理后台 - 护理内容")
@RestController
@RequestMapping("/yyzx/nurse_content")
@Validated
public class Nurse_contentController {

    @Resource
    private Nurse_contentService nurse_contentService;

    @PostMapping("/create")
    @Operation(summary = "创建护理内容")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_content:create')")
    public CommonResult<Integer> createNurse_content(@Valid @RequestBody Nurse_contentSaveReqVO createReqVO) {
        return success(nurse_contentService.createNurse_content(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新护理内容")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_content:update')")
    public CommonResult<Boolean> updateNurse_content(@Valid @RequestBody Nurse_contentSaveReqVO updateReqVO) {
        nurse_contentService.updateNurse_content(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除护理内容")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_content:delete')")
    public CommonResult<Boolean> deleteNurse_content(@RequestParam("id") Integer id) {
        nurse_contentService.deleteNurse_content(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得护理内容")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_content:query')")
    public CommonResult<Nurse_contentRespVO> getNurse_content(@RequestParam("id") Integer id) {
        Nurse_contentDO nurse_content = nurse_contentService.getNurse_content(id);
        return success(BeanUtils.toBean(nurse_content, Nurse_contentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得护理内容分页")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_content:query')")
    public CommonResult<PageResult<Nurse_contentRespVO>> getNurse_contentPage(@Valid Nurse_contentPageReqVO pageReqVO) {
        PageResult<Nurse_contentDO> pageResult = nurse_contentService.getNurse_contentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, Nurse_contentRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出护理内容 Excel")
    @PreAuthorize("@ss.hasPermission('yyzx:nurse_content:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportNurse_contentExcel(@Valid Nurse_contentPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<Nurse_contentDO> list = nurse_contentService.getNurse_contentPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "护理内容.xls", "数据", Nurse_contentRespVO.class,
                        BeanUtils.toBean(list, Nurse_contentRespVO.class));
    }

}